<template>
  <div class="finaceContainer">
    <div class="option">
      <span style="display:inline-block;padding-top:10px">
        <el-button type="primary" size="small" @click="Refresh()">刷新</el-button>
      </span>
      <div class="search">
        打款状态:
        <el-select v-model="financeStatus" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>电话号码:
        <el-input
          style="width:250px"
          placeholder="请输入电话号码搜索"
          prefix-icon="el-icon-search"
          v-model="phone"
        ></el-input>
        <span class="demonstration">开始日期</span>
        <div class="block">
          <el-date-picker v-model="startTime" type="date" placeholder="选择日期"></el-date-picker>
        </div>
        <span class="demonstration">结束日期</span>
        <div class="block">
          <el-date-picker v-model="endTime" type="date" placeholder="选择日期"></el-date-picker>
        </div>
        <el-button type="primary" @click="searchBtn()">搜索</el-button>
        <!-- <a :href="'http://192.168.3.21:9091/finance/poi?phone=' + phone + '&financeStatus='+ financeStatus+ '&userType=' + userType+ '&startTime=' + startTime + '&endTime=' + endTime">xiazaibiaoge</a> -->
             <!-- <a :href="'http://192.168.3.21:9091/finance/poi' + financeStatus + '/' +phone +'/' + userType">xiazaibiaoge</a> -->
        <!-- <a href="javascript:void(0)" @click="downLoad()">点击下载</a> -->
        <!-- <el-button type="info" plain size="small" @click="downLoad()">数据导出</el-button> -->
        <el-button type="info" plain>
          <a :href="'http://www.jfqiandai.com/finance/poi?phone=' + phone + '&financeStatus='+ financeStatus+ '&userType=' + userType+ '&startTime=' + startTime + '&endTime=' + endTime"  class="ahref">数据导出</a>
        </el-button>
        <!-- http://192.168.3.70:9091/finance/poi -->
      </div>
    </div>

    <el-table :data="List" border style="width: 100%">
      <el-table-column prop="index" label="序号"></el-table-column>
      <el-table-column prop="tradeNo" label="兑换单号" width="250"></el-table-column>
      <el-table-column prop="alipayName" label="支付宝名称"></el-table-column>
      <el-table-column prop="alipayAccount" label="支付宝账号"></el-table-column>
      <el-table-column prop="money" label="金额"></el-table-column>
      <el-table-column prop="phone" label="用户电话"></el-table-column>
      <el-table-column prop="account" label="操作人账号"></el-table-column>
      <el-table-column label="订单状态">
        <template slot-scope="scope">
          <el-button
            type="warning"
            size="small"
            v-show="scope.row.financeStatus == 0"
            @click="pendding(scope.row)"
          >未结算</el-button>
          <el-button type="success" size="small" v-show="scope.row.financeStatus == 1">已结算</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paginat">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage4"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>


<script>
import Vue from 'vue';
import axios from 'axios';
export default {
  data() {
    return {
      val: 1, //当前多少页
      currentPage4: 1,
      total: 0,
      List: [],
      dialogVisible: false,
      useriId: 0,
      startTime: "",
      endTime: "",
      phone: "",
      financeStatus: "",
      userType:0,
      options: [
        {
          value: "",
          label: "全部"
        },
        {
          value: 0,
          label: "未结算"
        },
        {
          value: 1,
          label: "已结算"
        }
      ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
//       exportBill:function () {

//         let url_post = Vue.prototype.api.apiList.EXPORT_BILL;

//         let params_post = {
//           orderStartDate: this.timepickerDateFormat(this.rangeTime[0]) || this.rangeTime[0] || '',
//           orderEndDate: this.timepickerDateFormat(this.rangeTime[1]) || this.rangeTime[1] || '',
//           prodCode: this.prodId,
//           promoteFlag: this.promotionSiteId,
//           policyStatusList: this.tableBillStateCheckedData,
//         };

//         Vue.axios.post(url_post,params_post,{responseType: 'arraybuffer'}).then((res) => {

//           let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];

//           fileDownload(res.data,fileName);  
//           //如果用方法一 ，这里需要安装 npm install js-file-download --save ,然后引用 var fileDownload = require('js-file-download')，使用详情见github;
// 　　　　　　  let blob = new Blob([res.data], {type: "application/vnd.ms-excel"}); 

// 　　　　　　  let objectUrl = URL.createObjectURL(blob); 
    
// 　　　　　  　window.location.href = objectUrl;  

// 　　　　}).catch(function (res) {}); },
    //刷新
    searchBtn() {
      if (this.startTime) {
        this.startTime =
          this.startTime.getFullYear() +
          "-" +
          (this.startTime.getMonth() + 1) +
          "-" +
          this.startTime.getDate();
      }
      if (this.endTime) {
        this.endTime =
          this.endTime.getFullYear() +
          "-" +
          (this.endTime.getMonth() + 1) +
          "-" +
          this.endTime.getDate();
      }
      this.formateDate(this.startTime);
      this.formateDate(this.endTime);
      this.getList();
    },

            //格式化日期
	 formateDate(date) {
		var date = new Date(date);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		var d = date.getDate();
    return y + "-" + m + "-" + d;
	},


    //下载/finance/download
    downLoad() {
      let url = "/finance/poi";
      let params = {
        // userType: this.userType,
        // endTime: this.endTime,
        // startTime: this.startTime,
        // financeStatus: this.financeStatus, //0未打款 1已打款
        // phone: this.phone
      };
      let aaa= {
        // responseType: 'blob'
        responseType: 'arraybuffer'
      };
      this.httpPost1(url,params,aaa,res => {
          let fileDownload = require('js-file-download');
          fileDownload(data, 'filename.csv');
          // console.log(res.data);
          // let fileName = res.headers['content-disposition'].match(/fushun(\S*)xls/)[0];
          // fileDownload(res,fileName);  
          // 　let blob = new Blob([res], {type: "application/vnd.ms-excel"}); 
          //   console.log(blob);
          // 　let objectUrl = URL.createObjectURL(blob); 
          //   console.log(objectUrl);
          // 　window.location.href = objectUrl;  
      })
      

    },
    //结算
    pendding(row) {
      this.$confirm("是否将状态更改为已结算?", "提示", {
        distinguishCancelAndClose: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/finance/editOne";
          let params = {
            id: row.id,
            financeStatus: 1
          };
          this.httpPut(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "更改成功"
              });
              this.dialogVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    //分页
    handleCurrentChange(val) {
      this.val = val;
      this.getList();
      console.log(`当前页: ${val}`);
    },
    //新增
    addUser() {
      //   this.$router.push("/addUser");
    },
    //刷新
    Refresh() {
      this.getList();
    },
    //查看
    handleClick(row) {
      //   this.$router.push("/checkUser?id=" + row.id);
    },
    //编辑
    EditClick() {},
    //删除
    DeleteClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let url = "/finance/editOne";
          let params = {
            id: row.id,
            status: 1,
            financeStatus: row.financeStatus
          };
          this.httpPut(url, params, res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功"
              });
              this.dialogVisible = false;
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //获取数据
    getList() {
      let url = "/finance/getList";
      let params = {
        pageNum: this.val,
        pageSize: 10,
        userType: 0,
        endTime: this.endTime,
        startTime: this.startTime,
        financeStatus: this.financeStatus, //0未打款 1已打款
        phone: this.phone
      };
      this.httpPost(url, params, res => {
        if (res.code == 200) {
          this.List = res.data.list;
          this.total = res.data.total;
          this.List.forEach((element, i) => {
            this.List[i].index = (this.val - 1) * 10 + i + 1;
          });
        } else {
          console.log("查询失败");
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.finaceContainer {
  .option {
  }
  .search {
    float: right;
    padding: 10px;
  }
  .block {
    display: inline-block;
    width: 200px;
  }
  .ahref{
    text-decoration: none;
    color: #888;
  }
}
</style>


<style>
.finaceContainer .el-button--success {
  margin-left: 0px !important;
}
.finaceContainer .el-input {
  width: 90%;
}
</style>



